<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '330px'
    },
    userNew: {
      type: String,
      default: new Array()
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      let NAME=[];
      for(let i=0;i<this.userNew.length;i++){
        NAME.push(this.userNew[i].HOUR)
      }
      let DATA=[];
      for(let i=0;i<this.userNew.length;i++){
        DATA.push(this.userNew[i].COUNT)
      }
      let option = {
        title: {
          text: '用户数据增长',
          left: 'center' // 设置标题居中
        },
        xAxis: {
          type: 'category',
          data: NAME
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data:DATA,
            type: 'line',
            smooth: true,
            label: {
              show: true, // 显示数值
              position: 'top' // 数值显示的位置
            }
          }
        ]
      };
      this.chart.setOption(option)
    }
  }
}
</script>
